package efg.tasks;

import interfacesFerrovia.ControleFerrovia;
import efg.Switch;
import efg.Track;

public class ChangeSwitchTask extends SchedulableTask {

	private Switch currentSwitch;
	private Track trackA;
	private Track trackB;

	public ChangeSwitchTask(int scheduledTime, Switch currentSwitch,
			Track trackA, Track trackB) {
		super(scheduledTime);
		assert (currentSwitch != null);
		assert (trackA != null);
		assert (trackB != null);
		this.currentSwitch = currentSwitch;
		this.trackA = trackA;
		this.trackB = trackB;
	}

	public Switch getSwitch() {
		return currentSwitch;
	}

	public Track getTrackA() {
		return trackA;
	}

	public Track getTrackB() {
		return trackB;
	}

	@Override
	public void execute(ControleFerrovia railwayControl) {
		assert (trackA != null && trackB != null);
		assert currentSwitch.getaTracks().contains(trackA.getId())
				|| currentSwitch.getbTracks().contains(trackA.getId());
		assert currentSwitch.getaTracks().contains(trackB.getId())
				|| currentSwitch.getbTracks().contains(trackB.getId());
		if (currentSwitch.getaTracks().contains(trackA.getId())) {
			railwayControl.mudarChave(currentSwitch.getId(), trackA.getId(),
					trackB.getId());
		} else {
			railwayControl.mudarChave(currentSwitch.getId(), trackB.getId(),
					trackA.getId());
		}
	}

}
